﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  MockPresenceProvider.cs
//    
// Abstract:
//
//  This module is an implementation of IPresenceProvider for use in unit
//  tests.
//
//--

using System;
using System.Collections.Generic;

namespace Microsoft.EnhancedReminders.Dispatcher.UnitTests
{
    /// <summary>
    /// Mock IPresenceProvider implementation for unit tests
    /// </summary>
    public class MockPresenceProvider : IPresenceProvider
    {
        private IDictionary<string, PresenceStates> _presenceStateMap;

        /// <summary>
        /// ctor
        /// </summary>
        public MockPresenceProvider()
        {
            _presenceStateMap = new Dictionary<string, PresenceStates>();
        }

        /// <summary>
        /// A dictionary where the key should be a user and the value should be
        /// their current presence. This is initially empty and it is up to
        /// individual unit tests to populate and modify this appropriately.
        /// </summary>
        public IDictionary<string, PresenceStates> PresenceStateMap
        {
            get
            {
                return _presenceStateMap;
            }
        }

        #region IPresenceProvider Members

        /// <summary>
        /// Returns presence for a given target. Returns "unknown" if an unknown user is specified.
        /// </summary>
        /// <param name="notification">The notification that the presence check is being performed for</param>
        /// <param name="target">SIP address of the target</param>
        public void GetPresenceAsync(NotificationItem notification, string target)
        {
            if (GetPresenceCompleted != null)
            {
                PresenceObtainedEventArgs returnResult = new PresenceObtainedEventArgs(notification, target);

                if (PresenceStateMap.ContainsKey(target))
                {
                    returnResult.Presence = _presenceStateMap[target];
                }

                GetPresenceCompleted.BeginInvoke(this, returnResult,
                    null /* asyncCallback */, this);
            }
        }

        /// <summary>
        /// Event thrown when a presence lookup is complete.
        /// </summary>
        public event EventHandler<PresenceObtainedEventArgs> GetPresenceCompleted;

        #endregion
    }
}
